|
|
|
|
|
|
|
|
When you're sorting records, the presence of an index for the sort field can significantly speed up the SQL query.  |
|
|
|
|
|
|
|
|
|
|
Figure C.7
The ORDER BY clause specifies the sort order of the dynaset. |
|
|
|
|
|
|
|
|
Listing C.13 SORT.TXTSpecifying the Sort Order of the Output Dynaset |
|
|
|
|
|
|
|
|
'*****************
'Single field sort
'*****************
SELECT * FROM Customers ORDER BY Lastname
'*******************
'Multiple field sort
'*******************
SELECT * FROM Customers ORDER BY Lastname, Firstname
'*********************
'Descending order sort
'*********************
SELECT * FROM Customers ORDER BY Lastname DESC, Firstname |
|
|
|
|
|
|
|
|
Using Aggregate Functions |
|
|
|
|
|
|
|
|
You can use the SELECT statement to perform calculations on the information in your tables by using the SQL aggregate functions. To perform the calculations, define them as a field in your SELECT statement, using the following syntax: |
|
|
|
|
|
|
|
|
The expression can be a single field or a calculation based on one or more fields, such as Quantity * Price or SQR(Datapoint). The Count function can also use the wild card * as the expression, because Count returns only the number of records. Table C.5 shows the 11 aggregate functions available in Microsoft SQL. |
|
|
|
|
|